{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "系数矩阵:\n",
      " [1.57719167]\n",
      "线性回归模型:\n",
      " RidgeCV(alphas=array([ 0.1,  1. , 10. ]), cv=None, fit_intercept=True,\n",
      "    gcv_mode=None, normalize=False, scoring=None, store_cv_values=False)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3X2U1dV97/H3B0QxV1AayRULOsmtRCim2I5eC7mNUWgMEszqtalJNXXqlbV0xRh11V7biDI02phErLk2CTEBY2IeV01wFBOikkRQzFCVyKAk0cGHEnlQRCMgOt/7x3mY8zTMYeb8zuPntRZrze/32+fM9ydyvue792/vrYjAzMwMYEStAzAzs/rhpGBmZllOCmZmluWkYGZmWU4KZmaW5aRgZmZZTgpmZpblpGBmZllOCmZmlnVQrQM4UEceeWS0tbXVOgwzs4aybt267RExfrB2DZcU2tra6O7urnUYZmYNRdLmctq5+8jMzLKcFMzMLMtJwczMspwUzMwsy0nBzMyynBTMzCzLScHMrAYKd72sl10wnRTMzKps8cpNdHb1ZBNBRNDZ1cPilZtqHJmTgplZVUUEu/bsY+nq3mxi6OzqYenqXnbt2VfziqHhZjSbmdWbiEDSgMe5JLFg7lQAlq7uZenqXgA6ZraxYO7UAV9XLa4UzMyGYShdQbmJIaMeEgI4KZiZDdlQu4Iy7XLlJpZacveRmdkQDaUrKDdxZNpljqH2FUPilYKkkZIeldQ1wPWPSOqRtEHSHUnHY2ZWSQfaFSSJsaNH5SWOBXOn0jGzjbGjR/W/butWOOkk+PGPk76FPNWoFC4FN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jKRZwD8D8yJib5ViS8pg9zwGmAasktRLqu91eYMPNpf7//aPImJfRDwDPEUqSTSqcu75AuB7ABHxEDCa1BpBzaqsf+/D1UxJ4ZfAcZLeKelgUgPJywvaZNZagjLXWqpzg95zuivlK6QSQqP3M8Mg9xwRr0TEkRHRFhFtpMZR5kVEd23CrYhy/t/+IamHCpB0JKnupKerGmVllXPPzwKnA0iaQiopNPMyysuBj6efQjoFeCUitlT6lzRN91FEvCnpE8CPST258PWI2NDMay2Vec+fAw4Dvp8eU382IubVLOhhKvOem0qZ9/xj4C8l9QBvAf8QETtqF/XwlHnPVwBflXQZqW6U8xv5S56kb5Pq/jsyPU5yDanNyYiIL5MaN5kD/AZ4HehIJI4G/m9oZmYV1kzdR2ZmNkxOCmZmluWkYGZmWU4KZmaW5aRgZmZZTgpmZpblpGBmZllOCmbDJOmk9Pr2oyX9t/R+BtNqHZfZUHjymlkFSPoXUsssHAo8HxHX1zgksyFxUjCrgPT6PL8ktX/DjIh4q8YhmQ2Ju4/MKuMPSK0xNYZUxWDWkFwpmFWApOWkdgd7JzAhIj5R45DMhqRpVkk1qxVJHwfejIg7JI0E1kg6LSLur3VsZgfKlYKZmWV5TMHMzLKcFMzMLMtJwczMspwUzMwsy0nBzMyynBTMzCzLScHMzLKcFMzMLOv/A3kJcL698zadAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np # 快速操作结构数组的工具\n",
    "import matplotlib.pyplot as plt  # 可视化绘制\n",
    "from sklearn.linear_model import Ridge,RidgeCV   # Ridge岭回归,RidgeCV带有广义交叉验证的岭回归\n",
    "\n",
    "\n",
    "# 样本数据集，第一列为x，第二列为y，在x和y之间建立回归模型\n",
    "data=[\n",
    "    [0.067732,3.176513],[0.427810,3.816464],[0.995731,4.550095],[0.738336,4.256571],[0.981083,4.560815],\n",
    "    [0.526171,3.929515],[0.378887,3.526170],[0.033859,3.156393],[0.132791,3.110301],[0.138306,3.149813],\n",
    "    [0.247809,3.476346],[0.648270,4.119688],[0.731209,4.282233],[0.236833,3.486582],[0.969788,4.655492],\n",
    "    [0.607492,3.965162],[0.358622,3.514900],[0.147846,3.125947],[0.637820,4.094115],[0.230372,3.476039],\n",
    "    [0.070237,3.210610],[0.067154,3.190612],[0.925577,4.631504],[0.717733,4.295890],[0.015371,3.085028],\n",
    "    [0.335070,3.448080],[0.040486,3.167440],[0.212575,3.364266],[0.617218,3.993482],[0.541196,3.891471]\n",
    "]\n",
    "\n",
    "\n",
    "#生成X和y矩阵\n",
    "dataMat = np.array(data)\n",
    "X = dataMat[:,0:1]   # 变量x\n",
    "y = dataMat[:,1]   #变量y\n",
    "\n",
    "\n",
    "\n",
    "# ========岭回归========\n",
    "model = Ridge(alpha=0.5)\n",
    "model = RidgeCV(alphas=[0.1, 1.0, 10.0])  # 通过RidgeCV可以设置多个参数值，算法使用交叉验证获取最佳参数值\n",
    "model.fit(X, y)   # 线性回归建模\n",
    "print('系数矩阵:\\n',model.coef_)\n",
    "print('线性回归模型:\\n',model)\n",
    "# print('交叉验证最佳alpha值',model.alpha_)  # 只有在使用RidgeCV算法时才有效\n",
    "# 使用模型预测\n",
    "predicted = model.predict(X)\n",
    "\n",
    "# 绘制散点图 参数：x横轴 y纵轴\n",
    "plt.scatter(X, y, marker='x')\n",
    "plt.plot(X, predicted,c='r')\n",
    "\n",
    "# 绘制x轴和y轴坐标\n",
    "plt.xlabel(\"x\")\n",
    "plt.ylabel(\"y\")\n",
    "\n",
    "# 显示图形\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
